﻿Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Input
Imports Microsoft.Xna.Framework.Graphics

Public Class Wizard
    Inherits BaseSprite
    Public Sub New()
        MyBase.New()
    End Sub

    Public Const StartPositionX As Integer = 125
    Public Const StartPositionY As Integer = 325
    Public Const WizardSpeed As Integer = 160
    Public Const BackgroundSpeed As Integer = 10

    Private mDirection As Vector2 = Vector2.Zero
    Private mSpeed As Vector2 = Vector2.Zero

    Private mPreviousKeyboardState As KeyboardState

    Private mGraphicsDevice As GraphicsDevice

    Public Enum WizardState
        Walking
        Sitting
    End Enum

    Private mCurrentState As WizardState
    Public Property CurrentState As WizardState
        Get
            Return mCurrentState
        End Get
        Set(ByVal value As WizardState)
            mCurrentState = value
        End Set
    End Property

    Public Overrides ReadOnly Property SpriteName As String
        Get
            Return "WizardSquare"
        End Get
    End Property

    Public Overrides Sub Load(ByVal currentContentManager As Microsoft.Xna.Framework.Content.ContentManager, ByVal theGraphicsDevice As GraphicsDevice)
        MyBase.Load(currentContentManager, theGraphicsDevice)
        Position = New Vector2(StartPositionX, StartPositionY)
    End Sub

    Public Sub Update(ByVal theGameTime As GameTime, ByVal theBackground As GameBackground)
        Dim kbsKeyboardState As KeyboardState = Keyboard.GetState
        UpdateMovement(kbsKeyboardState, theBackground)
        mPreviousKeyboardState = kbsKeyboardState
        If mDirection.X = MoveLeft Then
            If Position.X > 10 Then
                MyBase.Move(theGameTime, mSpeed, mDirection)
            Else
                mSpeed.X = BackgroundSpeed
                theBackground.Move(theGameTime, mSpeed, mDirection)
            End If
        ElseIf mDirection.X = MoveRight Then
            If Position.X < (GraphicsDevice.Viewport.Width - 10 - (SpriteTexture.Width * Scale)) Then
                MyBase.Move(theGameTime, mSpeed, mDirection)
            Else
                mSpeed.X = BackgroundSpeed
                theBackground.Move(theGameTime, mSpeed, mDirection)
            End If
        End If

    End Sub

    Public Sub UpdateMovement(ByVal theKeyboardState As KeyboardState, ByVal theBackground As GameBackground)
        If mCurrentState = WizardState.Walking Then
            mSpeed = Vector2.Zero
            mDirection = Vector2.Zero

            If theKeyboardState.IsKeyDown(Keys.Left) Then
                mSpeed.X = WizardSpeed
                mDirection.X = MoveLeft
            End If

            If theKeyboardState.IsKeyDown(Keys.Right) Then
                mSpeed.X = WizardSpeed
                mDirection.X = MoveRight
            End If

        End If
    End Sub

End Class
